package com.ruoyi.syrw.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.syrw.domain.vo.RefReportExcelVo;
import com.ruoyi.syrw.domain.bo.RefReportExcelBo;
import com.ruoyi.syrw.service.IRefReportExcelService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * report与excel关系
 *
 * @author zyb
 * @date 2024-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/syrw/refReportExcel")
public class RefReportExcelController extends BaseController {

    private final IRefReportExcelService iRefReportExcelService;

    /**
     * 查询report与excel关系列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<RefReportExcelVo> list(RefReportExcelBo bo, PageQuery pageQuery) {
        return iRefReportExcelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出report与excel关系列表
     */
    @SaCheckLogin
    @Log(title = "report与excel关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(RefReportExcelBo bo, HttpServletResponse response) {
        List<RefReportExcelVo> list = iRefReportExcelService.queryList(bo);
        ExcelUtil.exportExcel(list, "report与excel关系", RefReportExcelVo.class, response);
    }

    /**
     * 获取report与excel关系详细信息
     *
     * @param reportId 主键
     */
    @SaCheckLogin
    @GetMapping("/{reportId}")
    public R<RefReportExcelVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long reportId) {
        return R.ok(iRefReportExcelService.queryById(reportId));
    }

    /**
     * 新增report与excel关系
     */
    @SaCheckLogin
    @Log(title = "report与excel关系", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody RefReportExcelBo bo) {
        return toAjax(iRefReportExcelService.insertByBo(bo));
    }

    /**
     * 修改report与excel关系
     */
    @SaCheckLogin
    @Log(title = "report与excel关系", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody RefReportExcelBo bo) {
        return toAjax(iRefReportExcelService.updateByBo(bo));
    }

    /**
     * 删除report与excel关系
     *
     * @param reportIds 主键串
     */
    @SaCheckLogin
    @Log(title = "report与excel关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reportIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] reportIds) {
        return toAjax(iRefReportExcelService.deleteWithValidByIds(Arrays.asList(reportIds), true));
    }
}
